<template>
  <div class="login">
    <section class="form_container">
      <div class="manage_tip">
        <span class="title">房屋租赁管理系统</span>
        <el-form :model="loginUser" :rules="rules" ref="loginForm" label-width="100px" class="loginForm">
          <el-form-item label="姓名：" prop="name">
              <el-input v-model="loginUser.name"></el-input>
          </el-form-item>
           <el-form-item label="身份证：" prop="idCard">
              <el-input v-model="loginUser.idCard"></el-input>
          </el-form-item>
          <el-form-item label="电话号码：" prop="phone">
              <el-input v-model="loginUser.phone"></el-input>
          </el-form-item>   
          <el-form-item label="身份" prop="account">
            <el-select v-model="loginUser.type" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button  type="primary" class="submit_btn" @click="doLogin('loginForm')"> 确 认</el-button >   
          </el-form-item>
           <el-form-item  class="submit_btn1">
                 <el-button type="primary" class="submit_btn" @click="fh()"> 返 回</el-button>
           </el-form-item>
        </el-form>
      </div>
    </section>
  </div>
</template>

<script>
import jwt_decode from "jwt-decode";
import userApi from "../api/user";
import { setUser } from "../utils/auth";
import scheduleApi from "../api/schedule.js";

export default {
  name: "login",
  components: {},
  data() {
    return {
      notifyPromise: Promise.resolve(),
      loginUser: {
        name:'',
        idCard:'',
        phone:'',
        type:'',
      },
      options: [
        {
          value: "1",
          label: "管理员",
        },
        {
          value: "2",
          label: "用户",
        },
      ],
      rules: {
         name:[
              { required: true, message: '请输入姓名', trigger: 'blur' }
          ],
          idCard:[
              { required: true, message: '请输入身份证', trigger: 'blur' }
          ],
          phone:[
              { required: true, message: '请输入电话号码', trigger: 'blur' }
          ],
          type:[
              { required: true, message: '请选择身份角色', trigger: 'blur' }
          ]
      },
    };
  },
  methods: {
    fh() {
      this.$router.push("/login");
    },
    doLogin(formName) {
      let pojo = {
        name:this.loginUser.name,
        idCard:this.loginUser.idCard,
        phone:this.loginUser.phone,
        type:this.loginUser.type,    
      };
      userApi.zhuche(pojo).then((res) => {
        //登录成功之后的处理
        if (res.data.flag) {
          this.$message({
            message: "注册成功",
            type: "success",
          });
          this.$router.push("/login");
        } else {
          this.$message({
            message: "注册成功",
            type: "error",
          });

          this.loginUser.account = "";
          this.loginUser.password = "";
          this.loginUser.role = "";
        }
      });
    },
  },
};
</script>

<style scoped>
.submit_btn1{
margin-top: -2vh;
}
.login {
  position: relative;
  width: 100%;
  height: 100%;
  background: url(../assets/bg.jpg) no-repeat center center;
  background-size: 100% 100%;
}
.form_container {
  width: 370px;
  height: 210px;
  position: absolute;
  top: 20%;
  left: 34%;
  padding: 25px;
  border-radius: 5px;
  text-align: center;
}
.form_container .manage_tip .title {
  font-family: "Microsoft YaHei";
  font-weight: bold;
  font-size: 26px;
  color: #fff;
}
.loginForm {
  margin-top: 20px;
  background-color: #fff;
  padding: 20px 40px 20px 20px;
  border-radius: 5px;
  box-shadow: 0px 5px 10px #cccc;
}

.submit_btn {
  width: 100%;
}
.tiparea {
  text-align: right;
  font-size: 12px;
  color: #333;
}
.tiparea p a {
  color: #409eff;
}
</style>

